home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / etc_-_Configuration_Files / PCMCIA / SHARED < prev   
Text File  |  1999-09-17  |  3KB  |  134 lines

  1. #
  2. # shared 1.12 1998/10/19 09:55:48 (David Hinds)
  3. #
  4.  
  5. usage ()
  6. {
  7.     echo "usage: $0 [action] [device name]"
  8.     echo "  actions: start check stop suspend resume"
  9.     exit 1
  10. }
  11.  
  12. is_true ()
  13. {
  14.     [ "$1" = "y" -o "$1" = "Y" -o "$1" = "yes" -o "$1" = "YES" ]
  15. }
  16.  
  17. add_blkdev ()
  18. {
  19.     # usage: add_blkdev [device]
  20.     if is_true $DO_FSTAB ; then
  21.     echo "$1 $MOUNTPT ${FSTYPE:-auto} ${OPTS:-defaults} 0 0" >> /etc/fstab
  22.     fi
  23.     if is_true $DO_FSCK ; then
  24.     /sbin/fsck -Ta $1 || return 1
  25.     fi
  26.     if is_true $DO_MOUNT ; then
  27.     O=${OPTS:+-o $OPTS} ; FS=${FSTYPE:+-t $FSTYPE}
  28.     mount -v $O $FS $1 $MOUNTPT || return 1
  29.     fi
  30.     return 0
  31. }
  32.  
  33. add_parts ()
  34. {
  35.     # usage: add_parts [address] [parts]
  36.     RET=0
  37.     for PART in ${2:-""} ; do
  38.     # Get mount options for particular partitions
  39.     if [ "$PART" ] ; then
  40.         ADDRESS="$1,$PART"
  41.         unset DO_FSTAB DO_FSCK DO_MOUNT
  42.         . $0.opts
  43.     fi
  44.     add_blkdev /dev/$DEVICE$PART || RET=1
  45.     done
  46.     return $RET
  47. }
  48.  
  49. rm_blkdev ()
  50. {
  51.     # usage: rm_blkdev [device]
  52.     test -b $1 || return 1
  53.     fuser -s -k -m $1
  54.     if mount | fgrep "$1 on" ; then
  55.     umount -v $1 || return 1
  56.     fi
  57.     if is_true $DO_FSTAB ; then
  58.     fgrep -v $1 /etc/fstab > /etc/fstab.N
  59.     mv /etc/fstab.N /etc/fstab
  60.     fi
  61. }
  62.  
  63. rm_parts ()
  64. {
  65.     # usage: rm_parts [address] [parts]
  66.     BLK=/dev/$DEVICE
  67.     test -b $BLK || return 1
  68.     for PART in ${2:-""} ; do
  69.     if [ "$PART" ] ; then
  70.         ADDRESS="$1,$PART"
  71.         unset DO_FSTAB DO_FSCK DO_MOUNT
  72.         . $0.opts
  73.     fi
  74.     if is_true $DO_FSTAB ; then
  75.         fgrep -v "$BLK$PART " /etc/fstab > /etc/fstab.N
  76.         mv /etc/fstab.N /etc/fstab
  77.     fi
  78.     done
  79.     fuser -s -k -m /dev/${DEVICE}*
  80.     LIST=`mount | sed -ne "s+^\($BLK[0-9]*\) .*+\1+p"`
  81.     if [ "$LIST" ] ; then
  82.     for MT in $LIST ; do
  83.         umount -v $MT || return 1
  84.     done
  85.     fi
  86. }
  87.  
  88. chk_simple ()
  89. {
  90.     # usage: chk_simple [new-address]
  91.     ADDRESS=""
  92.     OLD=`set | grep -v '^OLD=' | md5sum`
  93.     ADDRESS=$1
  94.     . $0.opts
  95.     ADDRESS=""
  96.     NEW=`set | grep -v '^OLD=' | md5sum`
  97.     [ "$OLD" = "$NEW" ]
  98. }
  99.  
  100. chk_parts ()
  101. {
  102.     # usage: chk_parts [new-address]
  103.     OLD_ADDR=$ADDRESS
  104.     chk_simple $1 || return 1
  105.     if [ ! "$PARTS" ] ; then return 0 ; fi
  106.     for PART in $PARTS ; do
  107.     ADDRESS="$OLD_ADDR,$PART"
  108.     . $0.opts
  109.     chk_simple "$1,$PART" || return 1
  110.     done
  111. }
  112.  
  113. grep_stab ()
  114. {
  115.     # this should be cheaper than invoking "grep"
  116.     local CLASS DEV
  117.     while read SOCKET CLASS DRIVER INSTANCE DEV MAJOR MINOR ; do
  118.     if [ "$1" = "$DEV" ] ; then return 0 ; fi
  119.     done
  120.     return 1
  121. }
  122.  
  123. get_info ()
  124. {
  125.     SCHEME=`cat /var/run/pcmcia-scheme`
  126.     if [ ! "$SCHEME" ] ; then SCHEME="default" ; fi
  127.     grep_stab $1 < /var/run/stab || usage
  128. }
  129.  
  130. # A bit of stuff to do right away...
  131.  
  132. if [ $# -lt 2 ] ; then usage ; fi
  133. ACTION=$1 ; DEVICE=$2
  134.